package com.zhou.framework.job;

import com.zhou.framework.common.SpringFactory;
import com.zhou.framework.util.SettingUtil;
import com.zhou.util.DateUtil;
import com.zhou.util.TimeUtil;
import com.zhou.framework.quartz.job.JobTask;
import com.zhou.org.service.LogService;
import org.quartz.JobExecutionContext;

import java.util.Date;

/**
 * 系统业务日志清理任务
 */
public class SystemLoggerCleanTask extends JobTask {
    @Override
    public void run(JobExecutionContext context) {
        Date now = context != null ? context.getFireTime() : new Date();

        LogService logService = SpringFactory.getBean(LogService.class);
        int cleanDays = SettingUtil.getInteger("system","cleanDays",30);
        Date lastDt = TimeUtil.parseDate(DateUtil.getLastDay(now,cleanDays),"yyyyMMdd");
        logService.deleteLogBeforeDate(lastDt);
    }
}
